﻿using BAL;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Train_Railway.Home
{
    public partial class Login : System.Web.UI.Page
    {
        Control_Passenger var = new Control_Passenger();
        Passenger data = new Passenger();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_Login_Click(object sender, EventArgs e)
        {
            string username = Request.Form["Username"];
            string password = Request.Form["Password"];
            bool check = var.Passenger_CheckLogin(username, password);
            if (check == true)
            {
                Session["passenger"] = username;
                Response.Write("<script>alert('Login Success')</script>");
                Response.Redirect("~/Home/Index.aspx");
            }
            else
            {
                Response.Write("<script>alert('Username or Password invalid')</script>");
            }
        }

        protected void btn_Register_Click(object sender, EventArgs e)
        {
            string username = Request.Form["txt_User"];
            string password = Request.Form["txt_Pass"];
            string name = Request.Form["txt_Name"];
            DateTime birthday;
            string address = Request.Form["txt_Address"];
            string phones = Request.Form["txt_Phone"];
            string email = Request.Form["txt_Email"];


            DataTable dt = var.Passenger_GetByName(username);

            if (dt.Rows.Count > 0)
            {
                Response.Write("<script>alert('Username already exists ')</script>");
            }
            else
            {
                username = data.Username;
                password = data.Password;
                name = data.Name;
                birthday = data.Birthday;
                address = data.Address;
                phones = data.Phone;
                email = data.Email;

                var.Passenger_Insert(data);

                Response.Redirect("~/Home/Index.aspx");
            }
        }

 




    }
}